<?php
/*
  [EWEISHOP] Copyright(C) 2017 Elinkint Inc.
  This is NOT a freeware, use is subject to license terms
   
  OpenPlatformMiniProgramCodeManage.php 2018-05-30 13:56 cunx $
   
*/

namespace common\library\wechat\openplatform;

use common\component\wechat\Wechat;
use common\library\wechat\WechatApi;

/**
 * 第三方平台小程序代码管理
 * Class OpenPlatformMiniProgramCode
 * @package common\library\wechat\openplatform
 * @author cunx
 */
class OpenPlatformMiniProgramCodeManage extends WechatApi
{
    public static $apiType = 'miniProgram';
    public static $forceOpenPlatform = true;

    /**
     * 1. 为授权的小程序帐号上传小程序代码
     * @param int $templateId 代码库中的代码模版ID
     * @param string $extJson 第三方自定义的配置
     * @param string $version 代码版本号，开发者可自定义
     * @param string $description 代码描述，开发者可自定义
     * @return mixed
     * @author cunx
     */
    public static function commit(int $templateId, string $extJson, string $version, string $description)
    {
        $result = self::getInstance()->code->commit($templateId, $extJson, $version, $description);
        return Wechat::apiError($result);
    }

    /**
     * 2. 获取体验小程序的体验二维码
     * @param string|null $path 扫码后进入的页面路径
     * @return \EasyWeChat\Kernel\Http\Response |mixed
     * @author cunx
     */
    public static function getQrcode(string $path = null)
    {
        $result = self::getInstance()->code->getQrCode($path);
        return Wechat::apiError($result);
    }

    /**
     * 3. 获取授权小程序帐号的可选类目
     * @return array|bool|void
     * @author cunx
     */
    public static function getCategory()
    {
        $result = self::getInstance()->code->getCategory();
        return Wechat::apiError($result);
    }

    /**
     * 4. 获取小程序的第三方提交代码的页面配置
     * @return array|bool|void
     * @author cunx
     */
    public static function getPage()
    {
        $result = self::getInstance()->code->getPage();
        return Wechat::apiError($result);
    }

    /**
     * 5. 将第三方提交的代码包提交审核
     * @param array $itemList
     * @return mixed
     * @author cunx
     */
    public static function submitAudit(array $itemList)
    {
        $result = self::getInstance()->code->submitAudit($itemList);
        return Wechat::apiError($result);
    }

    /**
     * 7. 查询某个指定版本的审核状态
     * @param int $auditId  审核编号
     * @return mixed
     * @author cunx
     */
    public static function getAuditStatus(int $auditId)
    {
        $result = self::getInstance()->code->getAuditStatus($auditId);
        return Wechat::apiError($result);
    }

    /**
     * 8. 查询最新一次提交的审核状态
     * @return mixed
     * @author cunx
     */
    public static function getLatestAuditStatus()
    {
        $result = self::getInstance()->code->getLatestAuditStatus();
        return Wechat::apiError($result);
    }

    /**
     * 9. 发布已通过审核的小程序
     * @return mixed
     * @author cunx
     */
    public static function release()
    {
        $result = self::getInstance()->code->release();
        return Wechat::apiError($result);
    }

    /**
     * 10. 修改小程序线上代码的可见状态
     * @param string $action    设置可访问状态，发布后默认可访问，close为不可见，open为可见
     * @return mixed
     * @author cunx
     */
    public static function changeVisitStatus(string $action)
    {
        $result = self::getInstance()->code->changeVisitStatus($action);
        return Wechat::apiError($result);
    }

    /**
     * 11. 小程序版本回退
     * @return mixed
     * @author cunx
     */
    public static function rollbackRelease()
    {
        $result = self::getInstance()->code->rollbackRelease();
        return Wechat::apiError($result);
    }

    /**
     * 16. 小程序审核撤回
     * @return mixed
     * @author cunx
     */
    public static function withdrawAudit()
    {
        $result = self::getInstance()->code->withdrawAudit();
        return Wechat::apiError($result);
    }

}